package io.seata.factoryservice.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : author
 * @create 2022/8/22 16:41
 */
@Configuration
public class RabbitmqConfiguration {
    //定义交换机
    @Bean
    public TopicExchange exchangetopic(){
        return new TopicExchange("exchangetopic");
    }

    //定义naoh队列
    @Bean
    public Queue queuenaoh(){
        return new Queue("queuenaoh");
    }

    //定义nahco3队列
    @Bean
    public Queue queuenahco3(){
        return new Queue("queuenahco3");
    }

    //定义nh3队列
    @Bean
    public Queue queuenh3(){
        return new Queue("queuenh3");
    }


    //绑定naoh队列到交换机，指定路由
    @Bean
    public Binding bindingNaoh(TopicExchange exchange, Queue queuenaoh){
        return BindingBuilder.bind(queuenaoh).to(exchangetopic()).with("#.naoh.#");
    }

    //绑定nahco3队列到交换机，指定路由
    @Bean
    public Binding bindingNanco3(TopicExchange exchange, Queue queuenahco3){
        return BindingBuilder.bind(queuenahco3).to(exchangetopic()).with("#.nahco3.#");
    }

    //绑定nh3队列到交换机，指定路由
    @Bean
    public Binding bindingNh3(TopicExchange exchange, Queue queuenh3){
        return BindingBuilder.bind(queuenh3).to(exchangetopic()).with("#.nh3.#");
    }

}
